<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <ul>
      <li class="item">1</li>
      <li class="item">2</li>
      <li class="item">3</li>
      <li class="item">4</li>
      <li class="item">5</li>
      <li class="item">6</li>
      <li class="item">7</li>
      <li class="item">8</li>
    </ul>

    <script>
      var lis = document.querySelectorAll('li');
      var color;
      for(var i=0;i<lis.length;i++){
        if(i%2===0){
          lis[i].style.backgroundColor = 'pink';
        }
        else{ 
          lis[i].style.backgroundColor ='blue';
        }
        lis[i].onmouseover=function(){
          color = this.style.backgroundColor;
          this.style.backgroundColor='red';
        };
        lis[i].onpointerout=function(){
          this.style.backgroundColor=color;
        }
      }
    </script>
  </body>
</html>
